{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 实现打印n个\"+\"号                   (有1个参数，无返回值)\n",
    " 2. 现打印m行n列\"+\"号                  (有2个参数，无返回值)\n",
    " 3. 实现3个数的相加，返回计算结果        (有3个参数，有返回值)\n",
    " 4. 传入3个数，返回最大的数             (有3个参数，有返回值)\n",
    "  5. 书上第5章习题1 \n",
    "6. 书上第5章习题2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+++++\n",
      "++++++++++++++++++++\n",
      "++++++++++++++++++++++++++++++++++++++++\n"
     ]
    }
   ],
   "source": [
    "# 1. 实现打印n个\"+\"号   \n",
    "def print1(n): # 形参\n",
    "    for i in range(n):\n",
    "        print(\"+\",end=\"\")\n",
    "    print()\n",
    "\n",
    "# 5 调用函数时传入的参数 实参\n",
    "# 实际参数 可以常量 也可以是变量 也可以表达式\n",
    "print1(5)\n",
    "a = 20\n",
    "print1(a)\n",
    "print1(2*a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    " #2. 现打印m行n列\"+\"号 \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "++++++\n",
      "++++++\n",
      "++++++\n",
      "++++++\n",
      "++++++\n"
     ]
    }
   ],
   "source": [
    "def print2(m,n):\n",
    "    for i in range(m):\n",
    "        for j in range(n):\n",
    "            print(\"+\",end=\"\")\n",
    "        print()\n",
    "\n",
    "print2(5,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3. 实现3个数的相加，返回计算结果        (有3个参数，有返回值)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "60\n"
     ]
    }
   ],
   "source": [
    "def add(x,y,z):\n",
    "    return x+y+z\n",
    "\n",
    "print(add(10,20,30))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 4. 传入3个数，返回最大的数             (有3个参数，有返回值)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "15\n",
      "17\n"
     ]
    }
   ],
   "source": [
    "def max(a,b,c):\n",
    "    if a>b:\n",
    "        if a>c:\n",
    "            return a\n",
    "        else:\n",
    "            return c\n",
    "    else:\n",
    "        if b>c:\n",
    "            return b\n",
    "        else:\n",
    "            return c\n",
    "        \n",
    "print(max(10,5,7))\n",
    "print(max(10,15,7))\n",
    "print(max(10,15,17))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 8, 2, 2)\n"
     ]
    }
   ],
   "source": [
    "# 第5章 习题1\n",
    "def leapyear(n):\n",
    "    return n%400==0 or (n%100!=0 and n%4==0)\n",
    "\n",
    "# 5-2\n",
    "def count(s):\n",
    "    numQty = 0\n",
    "    charQty = 0\n",
    "    spaceQty = 0\n",
    "    otherQty = 0\n",
    "    for c in s:\n",
    "        # print(c)\n",
    "        if '0'<= c<='9':\n",
    "            numQty += 1\n",
    "        elif 'a'<= c <= 'z' or 'A'<= c <= 'Z':\n",
    "            charQty += 1\n",
    "        elif c == ' ':\n",
    "            spaceQty += 1\n",
    "        else:\n",
    "            otherQty += 1\n",
    "    return (numQty,charQty,spaceQty,otherQty)\n",
    "    \n",
    "print(count(\"abc123 hello @@\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
